package com.lsf.studentmanagerup.servlet.classbean;

import com.lsf.studentmanagerup.service.ClassBeanService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 李树飞
 */
@WebServlet(name = "CheckClassBeanServlet", urlPatterns = "/checkClassBean")
public class CheckClassBeanServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置字符编码
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("UTF-8");
        response.setContentType("text/html; charset=UTF-8");

        PrintWriter writer = response.getWriter();

        //获取id
        String id = request.getParameter("id");

        //调用服务层方法
        ClassBeanService classBeanService = new ClassBeanService();

        //将true或false发送回前端
        writer.print(classBeanService.checkClassBeanId(id));
        writer.flush();
        writer.close();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
